package myCollection;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * 迭代器遍历
 * @author Raymond
 * @create 2025/4/24 14:34
 */
public class CollectionIterator {
    public static void main(String[] args) {
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(1);
        objects.add(3);
        objects.add(2);
        //迭代器可以迭代遍历实现了Iterable接口的容器
        Iterator<Object> iterator = objects.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        //注意此时的迭代游标已经到头了，如果还需要重新遍历需要重新获取一下迭代器
//        Iterator<Object> iterator = objects.iterator();

    }
}
